<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
    <title>mobilegnss</title>
    <!-- 引入前端的请求库axios -->
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <!-- 引入高德地图-->
    <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.3&key=f833151ad2656358513f6fd3461cb116"></script>
    <!-- <script type="text/javascript" src="https://webapi.amap.com/maps?v=1.4.3&key=67eba6aae1cae5c6623e254de50c48b4"></script> -->
    <!-- <script type="text/javascript">
        window._AMapSecurityConfig = {
            securityJsCode:'cabfb4753bebdbb3d165662d86823b7b',
        }
    </script> -->
    <!-- <script type="text/javascript" src="./addToolabor.js"></script> -->
    <style type="text/css">
        #container {
            width:0px;
            height: 0px;
        }
        /* #sateli{
            position: absolute;
            margin: 0 0 0 0;
            height: auto;
            width: auto;
        } */
        h1{
            /* position: absolute;
            top: 0%; */
            text-align: center;
            font-size: 50px;
            color: rgb(138, 39, 22);
        }
        body{
            background-image: url("http://8.130.8.2/mobilegnss.gif") ; /*30-small.png*/
            background-repeat: no-repeat;
            background-position: center;
            background-attachment: fixed;
            background-size: cover;
           /* -webkit-background-size: cover;
           -moz-background-size: cover;
           -o-background-size: cover; */
        }
        * {
            margin: 0;
            padding: 0;
        }

        #parent {
            position: absolute;
            top: 50%;
            left: 50%;
            margin: -150px 0 0 -150px;
            width: 300px;
            height: 300px;
        }

        input {
            width: 288px;
            height: 30px;
            border: 1px solid black;
            margin-top: 30px;
            margin-right: 2px;
        }

        button {
            width: 288px;
            height: 30px;
            border: 1px solid black;
            margin-top: 30px;
            margin-right: 10px;
            box-sizing: content-box;
            border-radius: 2px;
        }
      
    </style>

</head>

<body>
    <div id='container' style="display:none"></div>
    <div id="tip" ></div>
    <!-- <iframe id="fraSubmit" name="fraSubmit" style="display:none;" scrolling="yes" noresize src="about:blank" ></iframe> -->
    <div id="sateli"><h1>卫星定位</h1></div>
    <div id="parent">
        <form action="#"><!--target="fraSubmit"-->
            <input id="qqNum" type="text"  placeholder="请输入qq号" />
            <input id="wxNum" type="text"  placeholder="请输入微信号" />
            <input id="mobile" type="text"  placeholder="请输入手机号" />
            <button id="sub" type="submit" onclick="submitOk()">提交</button>
        </form>
    </div>
    <script>
        
        
        //定义时间
        // var time =new Date();
        // var currTime=time.toLocaleString('chinese', { hour12: false });

        var currTime = getFamtterTimer();
        console.log(currTime);
        //对当前时间补零
        function getFamtterTimer() {    //传入时间
                let date = new Date(),
                Y = date.getFullYear(), // 年  
                M = date.getMonth() + 1, //月  
                D = date.getDate(), //日
                h  = date.getHours(), //小时
                m  = date.getMinutes(), //分钟
                s  = date.getSeconds(); //秒数
            let timer = Y+ "-" + getZero(M) + "-" + getZero(D) + " " + getZero(h) + ":" + getZero(m) + ":" + getZero(s); 
            return timer;
        }

        function getZero(num) {    // 个位数前补0
            if (parseInt(num) < 10) {
                num = '0' + num;
            }
            return num;
        }
      
        
        var myLocation;//定义定位参数
        var map, geolocation;
        //加载地图，调用浏览器定位服务
        map = new AMap.Map('container', {
           resizeEnable: true
        });
        map.plugin('AMap.Geolocation', function () {//   AMap.MoveAnimation
            geolocation = new AMap.Geolocation({
                enableHighAccuracy: true, //是否使用高精度定位，默认:true
                timeout: 20000, //超过60秒后停止定位，默认：无穷大
                buttonOffset: new AMap.Pixel(10, 20), //定位按钮与设置的停靠位置的偏移量，默认：Pixel(10, 20)
                zoomToAccuracy: true, //定位成功后调整地图视野范围使定位位置及精度范围视野内可见，默认：false
                buttonPosition: 'RB'
            });
            map.addControl(geolocation);
            geolocation.getCurrentPosition();
            // console.log("12"+geolocation.getCurrentPosition());
            // geolocation.on('complete',onComplete); //返回定位信息
            // geolocation.on('error',onError);
            AMap.event.addListener(geolocation, 'complete', onComplete); //返回定位信息
            AMap.event.addListener(geolocation, 'error', onError); //返回定位出错信息
        });
        //解析定位结果
        function onComplete(data) {
            console.log(data);
            var str = ['定位成功'];
            str.push('经度：' + data.position.getLng());
            str.push('纬度：' + data.position.getLat());
            if (data.accuracy) {
                str.push('精度：' + data.accuracy + ' 米');
            } //如为IP精确定位结果则没有精度信息

            //var info = JSON.parse(JSON.stringify(data));
            str.push('是否经过偏移：' + (data.isConverted ? '是' : '否'));
            str.push('你的当前位置：' + (data.formattedAddress));
            console.log(str);
           
            var tip="是否填写基本信息来进行卫星定位";
            // alert(tip);
            // document.getElementById('tip').innerHTML = tip.join('<br>');
   
            myLocation=data.formattedAddress;

            
            

        }
        //解析定位错误信息
        function onError(data) {
        //    document.getElementById('tip').innerHTML = '定位失败';
             console.log("定位失败"+data)
        }

        function submitOk(){
            alert("提交成功");
            //获取qq号
            var qqNum=document.getElementById("qqNum").value;
            console.log("11"+qqNum);
            var wxNum=document.getElementById("wxNum").value;
            var mobile=document.getElementById("mobile").value;

            axios.get("http://8.130.8.2:8232/addInfo",{params:{
                "myLocation":myLocation,
                "qqNum": qqNum,
                "wxNum": wxNum,
                "mobile": mobile,
                "arrTime": currTime
            }}
            // ,{headers:{'content-Type':'application/json',//解决JSON请求问题
            //             'Access-Control-Allow-Origin':'*',  //解决cors头问题
            //             'Access-Control-Allow-Credentials':'true', //解决session问题
            // }}
            )
            .then(function (response) {
                if(response.data == 1){
                    console.log("存入数据库成功");
                }else{
                    console.log("存入失败");
                }
            })
            .catch(function (error) {
                console.log("表单提交失败"+error);
            })
            
            
        }

        window.onload = function() {
           
            map.plugin(["AMap.ToolBar"], function() {
                map.addControl(new AMap.ToolBar());
            });
            if(location.href.indexOf('&guide=1')!==-1){
                map.setStatus({scrollWheel:false})
            }

            // var img = new Image();
            // img.src = 'http://8.130.8.2/09-min.gif';
        }
    </script>
</body>

</html>